package com.boarsoft.boar.soagov.svc.action;

import java.util.ArrayList;
import java.util.List;

import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.soagov.entity.SvcInfo;
import com.boarsoft.boar.soagov.svc.SvcBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.mongodb.core.MongoDao;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
/**
 * 流程图服务
 *
 * @author Mac_J
 */
@RestController
@RequestMapping("/svc/trace")
public class SvcTraceAction {
	@Autowired(required = false)
	private MongoDao mongoDao;

	@Autowired
	private SvcBiz svcBiz;

	@RequestMapping("/list.do")
	@Authorized(code = "svc.trace.list")
	public ReplyInfo<Object> list(String id, int pageNo, int pageSize) {
		SvcInfo svc = svcBiz.get(id);
		String db = svc.getCatalog();
		String code = svc.getCode();
		MongoCollection<Document> mc = mongoDao.getCollection(db, code);
		// Filters.eq("flowId", flowId);
		MongoCursor<Document> cur = mongoDao.list(mc, null, "startTime", pageNo, pageSize);
		List<Document> lt = new ArrayList<Document>();
		while (cur.hasNext()) {
			lt.add(cur.next());
		}
		int total = mongoDao.count(mc, null).intValue();
		PagedResult<Document> pr = new PagedResult<Document>(total, lt, pageNo, pageSize);
		return new ReplyInfo<Object>(true, pr);
	}
}